#include <iostream>
#include <vector>
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl17/point_cloud.h>
#include <pcl17/point_types.h>
#include <pcl17/io/pcd_io.h>
#include <pcl17/search/search.h>
#include <pcl17/search/kdtree.h>
#include <pcl17/visualization/cloud_viewer.h>
#include <pcl17/filters/passthrough.h>
#include <pcl17/segmentation/region_growing_rgb.h>


void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& msg)
{
    sensor_msgs::PointCloud2 output;
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr outCloud (new pcl::PointCloud<pcl::PointXYZRGB>);
//    pcl::fromROSMsg (*msg, *cloud);    // Publish the data

//    pcl::search::Search <pcl::PointXYZRGB>::Ptr tree = boost::shared_ptr<pcl::search::Search<pcl::PointXYZRGB> > (new pcl::search::KdTree<pcl::PointXYZRGB>);

//    pcl::IndicesPtr indices (new std::vector <int>);
//    pcl::PassThrough<pcl::PointXYZRGB> pass;
//    pass.setInputCloud (cloud);
//    pass.setFilterFieldName ("z");
//    pass.setFilterLimits (0.0, 1.0);
//    pass.filter (*indices);

//    pcl::RegionGrowingRGB<pcl::PointXYZRGB> reg;
//    reg.setInputCloud (cloud);
//    reg.setIndices (indices);
//    reg.setSearchMethod (tree);
//    reg.setDistanceThreshold (10);
//    reg.setPointColorThreshold (6);
//    reg.setRegionColorThreshold (5);
//    reg.setMinClusterSize (600);

//    std::vector <pcl::PointIndices> clusters;
//    reg.extract (clusters);

//    pcl::PointCloud <pcl::PointXYZRGB>::Ptr colored_cloud = reg.getColoredCloud ();
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "region_growing_segmentation");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subscribe<("chatter", 1000, chatterCallback);
  ros::spin();

  return 0;
}
